﻿@{
    ViewBag.Title = "GetPhone";
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>GetPhone</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.9.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <link href="../../Content/mdd_styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div>
        <span>Phone Number:<input id="phone" type="tel" autofocus="autofocus" maxlength="12" onkeypress='validate(event)' onkeyup='dashes(event)'/></span>

    </div>
    <div>
        <span>Last Name:<input id="lastName" type="text" maxlength="255" /></span>
    </div>
    <div>
        <span><input id="phoneButton" type="button" value="Submit" onclick="getData()"/> <input id="resetButton" type="button" value="Reset" onclick="reload()" /></span>
    </div>
    <div id="CustomerAjax">
        
    </div>
    <div id="submitButtonDiv">
        
    </div>

</body>
</html>
<script type="text/javascript">
    function getData() {
        var phone = document.getElementById("phone").value;
        var r = /(\D+)/g;
        phone = phone.replace(r, '');

        var lastName = document.getElementById("lastName").value;
        $('#CustomerAjax').html("<img src=\"/Content/Loading.gif\" alt=\"Loading\" >");
        var CustomerURL = "/UnAuthenticatedTicket/GetCustomerData?lastName=" + lastName + "&phone=" + phone;

        $.post(CustomerURL, function (data) {
            $('#CustomerAjax').html(data);
            $('#submitButtonDiv').html('<input id="ticketButton" type="button" value="This Is My Information" onclick="Ticket()" />');

        }).fail(function () { $('#CustomerAjax').html("Error") }) ;
        

    }
    function Ticket() {
        var customerID = $('#CustomerContactID').val();
        window.location.replace('/unauthenticatedticket/create/' + customerID);
    
    }
    function reload() {
        location.reload();
    }
    function validate(evt) {
        var theEvent = evt || window.event;
        var key = theEvent.keyCode || theEvent.which;
        key = String.fromCharCode(key);
        var regex = /[0-9]|\./;
        if (!regex.test(key)) {
            theEvent.returnValue = false;
            if (theEvent.preventDefault) theEvent.preventDefault();
        }

    }
    function dashes(evt) {

        var key = event.which || event.keyCode || event.charCode;

        if (key != 8) {
            var f = document.getElementById("phone");

            var r = /(\D+)/g,
                npa = '',
                nxx = '',
                last4 = '';
            f.value = f.value.replace(r, '');
            npa = f.value.substr(0, 3);
            nxx = f.value.substr(3, 3);
            last4 = f.value.substr(6, 4);
            f.value = npa + '-' + nxx + '-' + last4;
        }
    }
</script>